﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace GameViewer.Core
{
    public class IconManager : Singleton<IconManager>
    {
        private ImageList mImageList;

        public IconManager()
        {
            mImageList = new ImageList();
            mImageList.ColorDepth = ColorDepth.Depth32Bit;
            mImageList.Images.Add("play", Properties.Resources.control);
            mImageList.Images.Add("pause", Properties.Resources.control_pause);
            mImageList.Images.Add("stop", Properties.Resources.control_stop_square);
            mImageList.Images.Add("export", Properties.Resources.document_export);
            mImageList.Images.Add("globe", Properties.Resources.document_globe);
            mImageList.Images.Add("image", Properties.Resources.document_image);
            mImageList.Images.Add("number", Properties.Resources.document_number);
            mImageList.Images.Add("text", Properties.Resources.document_text);
            mImageList.Images.Add("list", Properties.Resources.document_list);
            mImageList.Images.Add("property", Properties.Resources.property_blue);
        }

        public ImageList ImageList
        {
            get
            {
                return mImageList;
            }
        }

        public void AddImage(string key, Image image)
        {
            if (mImageList.Images.ContainsKey(key) == false)
            {
                mImageList.Images.Add(key, image);
            }
        }

        public Image this[string key]
        {
            get
            {
                if (mImageList.Images.ContainsKey(key))
                {
                    return mImageList.Images[key];
                }
                return null;
            }
        }

        public Icon GetIcon(string key)
        {
            if (mImageList.Images.ContainsKey(key))
            {
                Image image = mImageList.Images[key];
                return Icon.FromHandle(((Bitmap)image).GetHicon());                
            }
            return null;
        }       
    }
}
